using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using System.Collections;
using NovodexWrapper;

namespace marbletrack
{
    public class PhysicsBlock : PhysicsControlledObject
    {
        //readonly variables used to controll the size of the blocks
        public readonly float WIDTH = 400;
        public readonly float HEIGHT = 400;
        public readonly float DEPTH = 400;
        public readonly float SCALE;
        private readonly NxVec3 DIMENSIONS;

        //list of different coloured models to use for blocks
        private ModelClass[] modelList = { Game1.GreeenCube, Game1.RedCube, Game1.BlueCube, Game1.BlueCube, Game1.RedCube, Game1.GreeenCube };


        public PhysicsBlock(Matrix transform, float scale)
        {
            SCALE = scale;
            WIDTH *= SCALE;
            HEIGHT *= SCALE;
            DEPTH *= SCALE;
            DIMENSIONS = new NxVec3(WIDTH / 2, HEIGHT / 2, DEPTH / 2);

            SetupVariables(transform);
            model_.FlagTextured = true;
        }

        protected override void SetupVariables(Matrix transform)
        {
            model_ = modelList[Game1.Ran.Next(0, modelList.Length)]; //pics a random coloured cube model for the block
            //model_ = modelList[1];
            density_ = 1f;
            transform_ = transform;

            //Create physics actor for the block
            NxShapeDesc blockShapeDesc = new NxBoxShapeDesc(NxMat34.Identity, NxShapeFlag.USE_DEFAULT, 0, Physics.BlockMaterial.MaterialIndex, "block", DIMENSIONS);
            NxBodyDesc blockBodyDesc = new NxBodyDesc();
            NxActorDesc blockActorDesc = new NxActorDesc(blockShapeDesc, blockBodyDesc, density_, MathConversion.ToNxMat34(transform_));
            actor_ = Physics.PhysicsScene.createActor(blockActorDesc);

            //Set blocks physics group
            actor_.setGroup(Physics.BLOCK_PHYSICS_GROUP);
        }

        public override void Draw()
        {
            transform_ = Matrix.CreateScale(SCALE) * transform_; //scales the model to the correct size before drawing (so the blocks draw the same size as the physics actors)
            base.Draw();
        }
    }
}
